<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">


<script id="hexo-configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    hostname: new URL('http://yoursite.com').hostname,
    root: '/',
    scheme: 'Pisces',
    version: '7.6.0',
    exturl: false,
    sidebar: {"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},
    copycode: {"enable":false,"show_result":false,"style":null},
    back2top: {"enable":true,"sidebar":false,"scrollpercent":false},
    bookmark: {"enable":false,"color":"#222","save":"auto"},
    fancybox: false,
    mediumzoom: false,
    lazyload: false,
    pangu: false,
    comments: {"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},
    algolia: {
      appID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    },
    localsearch: {"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},
    path: '',
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}
  };
</script>

  <meta name="description" content="about the single image super-resolution and face hallucination">
<meta property="og:type" content="website">
<meta property="og:title" content="SRCNN">
<meta property="og:url" content="http://yoursite.com/index.html">
<meta property="og:site_name" content="SRCNN">
<meta property="og:description" content="about the single image super-resolution and face hallucination">
<meta property="og:locale" content="en_US">
<meta property="article:author" content="Z.J. Jiang">
<meta property="article:tag" content="SISR">
<meta property="article:tag" content=" FH">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="http://yoursite.com/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome: true,
    isPost: false
  };
</script>

  <title>SRCNN</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-meta">

    <div>
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">SRCNN</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
        <p class="site-subtitle">SISR-FH</p>
  </div>

  <div class="site-nav-toggle">
    <div class="toggle" aria-label="Toggle navigation bar">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>
</div>


<nav class="site-nav">
  
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>Home</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>Tags</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>Categories</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>Archives</a>

  </li>
  </ul>

</nav>
</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content">
            

  <div class="posts-expand">
        
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block home" lang="en">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2022/03/06/STM32/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="Z.J. Jiang">
      <meta itemprop="description" content="about the single image super-resolution and face hallucination">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="SRCNN">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          
            <a href="/2022/03/06/STM32/" class="post-title-link" itemprop="url">STM32</a>
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">Posted on</span>

              <time title="Created: 2022-03-06 00:30:15" itemprop="dateCreated datePublished" datetime="2022-03-06T00:30:15+08:00">2022-03-06</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">Edited on</span>
                <time title="Modified: 2022-03-16 23:20:40" itemprop="dateModified" datetime="2022-03-16T23:20:40+08:00">2022-03-16</time>
              </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>讲解<br>外设原理+器件原理+ST官方参考手册+ST标准库 = 外设开发</p>
<p>HAL库。</p>
<ul>
<li>开发板的介绍</li>
<li>视频思路的讲解。</li>
</ul>
<p>全功能开发板<br>电机开发板</p>
<p>ARM：芯片内核设计公司<br>Advanced RISC Machines</p>
<p>Cortex M4<br>RGB-LGBT</p>
<p>Cortex M7<br>STM32 - ST公司</p>
<p>电机开发板系列</p>
<p>HAL库： 硬件抽象层<br>抽象思想<br>封装出一层通用性的接口，标准化了一套初始化和使用流程，大大提高了代码的通用性。<br>GPIO: function() -&gt; F1\F4\F7\H7</p>
<p>MIddle level</p>
<p>CubeMX 只支持HAL库<br>low layer ll 库<br>Hardware Abstraction Layer(HAL)</p>
<p>中间件，cubemx low layer</p>
<p>原理介绍：各种协议、各种器件原理<br>搭配CubeMX: 生成代码</p>
<p>DSP：数字信号处理<br>FPU：浮点运算单元</p>
<p>IAR CubeIDE keil</p>
<p>STM32介绍 ST: 意法半导体 M: 微电子 32总线宽度。 MCU微控制器（单片机）微型计算机系统<br>选型和开发介绍。<br>1、参考手册：一般描述这款芯片，软件上怎么使用。<br>2、数据手册：大致的介绍功能等。</p>
<p>引脚分配<br>电源IO<br>晶振IO<br>下载IO<br>BOOT IO<br>复位IO<br>GPIO</p>
<p>原理图绘制-&gt;PCB layout-&gt;程序编写。</p>
<p>寄存器编程</p>
<p>函数库编程</p>
<p>寄存器：外设的地址</p>
<p>FLASH、SRAM地址</p>
<p>GPIO内部结构框图</p>
<p>IDE: 为你设置好了堆栈</p>
<p>配置：<br>1、运行环境管理工具<br>2、从我们的库包中添加。</p>
<p>Dummy-Robot:<br>startup:<br>启动文件 xxxx.s</p>
<p>Drivers<br>    CMSIS<br>        Device: CMSIS 的相关东西</p>
<p>system_stm32f1xx.c f1 的启动文件？</p>
<p>通过总线的形式，可以很好将各种外设分离开，可以独立将各种外设来控制它的是能与否。控制外设是能与否就是控制这个外设的时钟。时钟频率越高，耗能越高。</p>
<p>仿真器：<br>JTAG接口<br>SWD接口</p>
<p>软件开发步骤：<br>1、使能GPIOB的外设时钟。外设基地址：0x40021000 APB2 外设时钟使能寄存器地址：偏移0x18</p>
<p>2、通过查阅参考手册的GPIO章节，知道了要配置推挽输出模式。通过端口配置表展示的寄存器来进行配置。<br>外设基地址+偏移。GPIOB 0x40010C00 偏移：CRL偏移：0x00 ODR偏移：0x0c</p>
<p>3、使用HAL库之后，就是用HAL库来初始化就好了吧。</p>
<p>2、根据需要配置的功能寻找参考手册</p>
<h1 id="define-GPIOB-CLK-volatile-unsigned-int-0x40021000-0x18"><a href="#define-GPIOB-CLK-volatile-unsigned-int-0x40021000-0x18" class="headerlink" title="define GPIOB_CLK ((volatile unsigned int )(0x40021000 + 0x18))"></a>define GPIOB_CLK (<em>(volatile unsigned int </em>)(0x40021000 + 0x18))</h1><h1 id="define-GPIOB-CRL-volatile-unsigned-int-0x40021000-0x18"><a href="#define-GPIOB-CRL-volatile-unsigned-int-0x40021000-0x18" class="headerlink" title="define GPIOB_CRL ((volatile unsigned int )(0x40021000 + 0x18))"></a>define GPIOB_CRL (<em>(volatile unsigned int </em>)(0x40021000 + 0x18))</h1><h1 id="define-GPIOB-ODR-volatile-unsigned-int-0x40021000-0x18"><a href="#define-GPIOB-ODR-volatile-unsigned-int-0x40021000-0x18" class="headerlink" title="define GPIOB_ODR ((volatile unsigned int )(0x40021000 + 0x18))"></a>define GPIOB_ODR (<em>(volatile unsigned int </em>)(0x40021000 + 0x18))</h1><p>int main(void)<br>{<br>    // 使能GPIO时钟<br>    GPIOB_CLK |= (1&lt;&lt;3)</p>
<pre><code>// 配置推挽输出模式
GPIOB_CRL &amp;= ~(0xf&lt;&lt;(4*0))
GPIOB_CRL |= 2 &lt;&lt; 0

// 参考原理图进行相应的配置。
GPIO_ODR &amp;= ~()
GPIOB_ODR |= ()
</code></pre><p>}</p>
<p>寄存器编程-&gt;库编程</p>
<p>1、代码可读性差<br>2、二次开发难度大<br>3、每次写程序都要查手册，麻烦</p>
<p>STM32的外设寄存器组织形式：<br>基于 基地址+寄存器偏移。</p>
<p>GPIO // GPIO初始化结构体。<br>HAL_GPIO_Init()</p>
<p>1、循环和判断<br>找到GPIO的偏移位置。</p>
<p>先读<br>先清空对应位<br>写回</p>
<p>HAL固件包中的内容：<br>1、Documentation<br>说明文档<br>2、Drivers<br>包含BSP\CMSIS\HAL_Driver<br>3、Middlewares中间件<br>4、project<br>官方提供的各种工程实例，包含外设如何使用，以及外设与中间件的耦合。非常又参考价值。<br>5、Utilities<br>通用的一些文件，不重要。</p>
<p>使用HAL库<br>1、自己移植, .c .h文件</p>
<ol>
<li>使用CubeMx配置</li>
</ol>
<p>知识的运用与BSP介绍。</p>
<p>什么是板级支持包<br>BSP Board Support Package 是介于主板硬件和操作系统中驱动层程序之间的一层，<br>一般认为它属于操作系统一部分，主要是实现对操作系统的支持，为上层的驱动程序提供<br>访问硬件设备寄存器的函数包，使之能够更好的运行于硬件主板。</p>
<p>用户应用层</p>
<p>板级支持包: 对板上的资源功能给出实现，并且提供用户程序的接口。以LED等为例，用户应用程序不需要知道GPIO的硬件特点，他只需要知道调用这个函数就可以点亮LED等。<br>应用程序操作灯和按钮，hal程序操作io引脚，板级支持包接收应用程序操作，转化成引脚操作</p>
<p>底层驱动</p>
<p>LED灯的板级支持包：<br>初始化GPIO<br>点亮、熄灭 LED</p>
<p>KEY的板级支持包<br>初始化GPIO(配置为输入，读取GPIO)</p>
<p>判断按键是否初始化<br>读取GPIO的电平引脚状态。</p>
<p>板级支持包的构建：看起来实际上就是给上层应用提供一个API</p>
<p>STM32程序的启动流程。<br>程序的启动流程</p>
<p>芯片商店以后回触发复位异常。<br>并且回跳转到中断向量表特定偏移位置。获取里面的内容取指执行。</p>
<p>触发复位异常-&gt;中断向量表-&gt;用户程序。</p>
<ol>
<li>初始化堆栈指针</li>
<li>设置PC指针的值</li>
<li>设置中断向量表</li>
<li>设置系统时钟。</li>
<li>调用C库函数__main 初始化堆栈的工作，最终回跳转到用户程序。 </li>
</ol>
<p>修改复位异常内的内容，就可以让处理器去执行我们指定的操作</p>
<p>STM32的RCC外设<br>    RCC-复位和时钟控制</p>
<p>STM32 RCC知识</p>
<p>STM32的复位功能<br>    系统复位<br>    电源复位<br>    后备域复位 保存用户配置的。</p>
<p>时钟频率高。功率高。<br>STM32的时钟<br>    时钟简单理解为 “心跳”。STM会根据程序给定他的时钟节拍来工作。<br>    STM32主时钟</p>
<p>STM32的时钟树设计</p>
<p>使用</p>
<p>对于STM32上的时钟，具体怎么配置，根据需求决定。<br>时钟频率越高，功耗也会更高。<br>另一方面要考虑芯片的工作条件，根据芯片运行的工作条件选取不同的频率。</p>
<p>F429：<br>外部时钟/M（分频因子 ）</p>
<p>STM32的中断<br>中断是指计算机运行过程中，需要，，，，</p>
<p>中断优先级。<br>通过 嵌套向量中断控制器。 来实现优先级<br>nvic_enableirq<br>nvic_disableirq</p>
<p>EXTI扩展中断和事件控制器<br>EXTI工程示例讲解。<br>事件—-&gt;中断 事件—&gt;事件</p>
<p>EXTI外设可以大致概括为两个功能：</p>
<ul>
<li>捕获外部输入等事件 </li>
<li>生成EXTI中断等中断请求</li>
</ul>
<p>事件产生中断，然后调用相关的函数。</p>
<p>外部触发，软件触发，生成中断，唤醒CPU</p>
<p>工程演示：<br>STM32CubeMX 生成代码。</p>
<p>How to Use this driver</p>
<p>HAL_EXTI_SetConfigLine()</p>
<p>中断-&gt;中断向量表-&gt;偏移：入口地址-&gt;中断服务函数。<br>最终跳转到对应的中断服务函数中寻找。<br>stm32f1xx_it.c 或者放在最后的服务函数。</p>
<p>通过EXTI线，捕获EXTI线事件，并且生成中断，在中断中反转LED灯的状态，并且清除EXTI中断标志(中断标志要清除。不然会进入死循环)</p>
<p>SysTick-系统定时器<br>内核的外设<br>外设的原理及功能介绍<br>Systick定时器特性。</p>
<p>属于COrtex-M内核中的一个外设。内嵌在NVIC中。</p>
<p>计数宽度：<br>24bit来存储数据，2^24</p>
<p>向下递减：<br>计数器的工作模式，</p>
<p>计数器的工作周期：<br>1/CLKSource, 1/72Mhz</p>
<p>当重装在数值寄存器的值减到0，可以产生一个中断。</p>
<p>SysTick系统定时器是属于Cortex-M内核的外设。内核外设。</p>
<p>功能：<br>用于操作系统，用于产生时基，维持</p>
<p>延时功能的配置。 HAL_Delay函数就是根据Systick使用的。</p>
<p>HAL库驱动框架简述</p>
<ul>
<li>外设初始化</li>
<li>外设使用</li>
</ul>
<ol>
<li>对外设的封装</li>
</ol>
<ul>
<li>对外设的封装 xx_HandleTypeDef(XX外设句柄结构体，xx表示任意外设名)<ul>
<li>instatnce xx_TypeDef类型， 存放基地址，例如GPIO的文件。</li>
<li>Init成员 xx_InitTypeDef类型</li>
<li>Hdma *成员(DMA_HandleTypeDef类型，可能一个句柄结构体中有多个)</li>
<li>其他资源 LOCK STATUS HAL_LockTypeDef 类型 HAL_xx_StateTypeDef类型</li>
</ul>
</li>
</ul>
<ol>
<li><p>外设初始化使用方法</p>
<ul>
<li>HAL_xx_init, 参数一般为xx外设的句柄结构体</li>
<li>HAL_xx_MspInit，参数一般为xx外设的句柄结构体 将外设使用到的底层资源初始化完成 Init the low level hardware : GPIO, CLOCK, NVIC… 为一个弱定义，需要我们用户来自己实现。</li>
<li>其他Init方法：具体参考，HAL库，How to use this Driver</li>
</ul>
</li>
<li><p>外设使用逻辑</p>
<ul>
<li>阻塞轮询(Polling)<br>  xx_start<br>  xx_read、write<br>  等等函数</li>
<li>中断<br>  xx_start_it<br>  xx_read\write_it<br>  xx_xx_it 等等中断启动函数。特指，函数名以IT结尾。</li>
<li>DMA<br>  xx_start_dma — DMA功能<br>  xx_read\write_dma<br>  xx_xx_dma</li>
<li>其他功能 标志的查询\清楚 中断使能，失能。</li>
</ul>
</li>
<li><p>全面了解：How to User This Driver</p>
</li>
</ol>
<p>Debug功能及Debug方法简述</p>
<ul>
<li>硬件调试</li>
<li>打印调试</li>
<li>调试器调试</li>
</ul>
<p>通讯的基本概念：<br>全双工，半双工。串行 并行 等。</p>
<p>USART</p>
<p>UART主要用来产生相关接口的协议信号。UART广泛引用与串口通信中，扮演者传输器的角色。</p>
<p>RS-232标准介绍。</p>
<p>一般开发板上使用的点评标准与通讯使用的电平·标准不同。</p>
<p>UART外设的使用：</p>
<ol>
<li>定义一个UART_HandleTypeDef结构体句柄</li>
<li>通过HAL_UART_MspInit函数来实现要做的功能<ul>
<li>使能UART外设的时钟</li>
<li>配置UART使用的引脚模式</li>
<li>如使用中断，需要将中断配置好。</li>
<li>HAL_UART_INIT</li>
</ul>
</li>
</ol>
<p>DMA-直接存储器访问控制器</p>
<p>外设与存储器，存储器与存储器之间，提供高速数据传输。</p>
<p>DMA就是CPU的助手、数据搬运工。<br>DMA控制器的实现基于复杂的总线架构。</p>
<p>1、DMA请求<br>2、通道选择<br>3、FIFO功能<br>4、数据搬运的目标地址</p>
<p><strong>DMA的功能就是建立起一个数据传输通道。</strong></p>
<p>串口DMA，串口接收数据，放到内存中。</p>
<ol>
<li>建立传输通道<br> 存储器-&gt;存储器<br> 外设-&gt;存储器<br> 存储器-&gt;外设</li>
</ol>
<ol>
<li>确定传输对象<br> 具体的功能<pre><code> UART-内存
 内存数据-UART
</code></pre></li>
<li>传输的细节<br> 确定由谁产生DMA请求。外设的DMA请求外设通道<br> 通道的优先级<br> 确定传输数据双方数据的格式<br> 确定数据是否需要一直采集（循环模式）</li>
</ol>
<p>单次传输<br>突发传输。</p>
<p>串口外设数据寄存器地址。不能地址。内存地址应该是要递增的。</p>
<p>HAL库中的DMA功能实例<br>HandleTypeDef instance</p>
<p>使用cubemx 进行初始化代码。<br>实际的代码逻辑。</p>
<p>串口外设模式下的演示。</p>
<p>EEPROM<br>I2C通信协议<br>广泛地使用在系统内多个继承电路间的通讯。<br>支持多设备的总线。<br>一个I2C总线两条总线。SDA SCL</p>
<p>每个连接到总线的设备都有一个独立的地址，主机可以利用这个地址</p>
<p>多个主机同时使用总线时，为了防止数据冲突，会利用冲裁的方式。</p>
<p>I2C的协议层<br>通信的起始，终止信号。</p>
<p>I2C总线上的每个设备都有自己的独立地址。</p>
<p>相应。</p>
<p>如何使用STM32产生I2C协议信号。</p>
<p>软件模式协议：使用CPU直接控制通讯引脚的点评，产生出符合通讯协议标准的逻辑。</p>
<p>硬件实现协议：</p>
<p>STM32的I2C控制器特性介绍<br>I2C 读写EEPROM实验。</p>
<p>Fat文件系统的移植。<br>1、把FatFS的源码拷贝到工程文件夹目录</p>
<p>新建一个10x的工程，然后把axf拷贝过去，然后烧录，需要准备keil 安装包。<br>芯片包等。</p>
<p>SPI QSPI的通信内容<br>FLASH固件来实现</p>
<p>Serial Peripheral Interface</p>
<p>SPI的写入过程，手动查出，然后</p>
<ol>
<li>初始化通信使用的目标引脚和时钟。</li>
<li>使能spi外设的时钟。</li>
<li>配置spi外设的模式，速率，等</li>
<li>编写按字节收发的函数。<br>将片选信号拉低，<br>等待数据发送完成标志。<br>将数据写入spi数据寄存器中</li>
</ol>
<p>CAN 是控制完了过总西南。<br>CAN通信并不是以时钟信号来进行同步的，它是一种异步通信，CAN_High,CAN_Low两条信号线，<br>共同构成一组差分信号线，以差分信号的形式进行通信。</p>
<p>CAN物理层组要分为闭环和开环总线网络两种，一个适合于告诉通讯，一个适合于远距离通讯。<br>闭环速度快，传输距离段<br>开环</p>
<p>差分信号的有点，抗干扰，定位精确。</p>
<p>CAN的波特率及位同步<br>CAN时异步通信，没有时钟信号线。<br>CAN还会使用 “位同步”的方式来抗干扰、吸收误差，实现对总线电平</p>
<p>通讯的波特率</p>
<p>CAN使用两个差分信号线，只能表达一个信号，<br>复杂的协议来补充这一点。<br>报文。</p>
<p>差分信号。<br>数据帧。<br>数据帧<br>遥控帧<br>错误帧<br>过载帧<br>帧间隔</p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

        
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block home" lang="en">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2022/01/02/csapp/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="Z.J. Jiang">
      <meta itemprop="description" content="about the single image super-resolution and face hallucination">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="SRCNN">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          
            <a href="/2022/01/02/csapp/" class="post-title-link" itemprop="url">csapp</a>
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">Posted on</span>

              <time title="Created: 2022-01-02 11:03:44" itemprop="dateCreated datePublished" datetime="2022-01-02T11:03:44+08:00">2022-01-02</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">Edited on</span>
                <time title="Modified: 2022-01-16 16:11:49" itemprop="dateModified" datetime="2022-01-16T16:11:49+08:00">2022-01-16</time>
              </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <p>instruction set architecture, or ISA<br>virtual address<br>the programe counter</p>
<p>virtual address and programe counter</p>
<p>register file contain 16 named locations storing 64-bit values.<br>These registers can hold addresses(corresponding to C pointer) // 保存的是地址。！！！！不管什么，保存的都是地址。。。<br>The condition code registers hold status informatino about the most recently executed arithemetci or logical instruction. These are used to implement condition</p>
<p>A set of vector resiters can each hold one or more integer or floating-point values</p>
<p>Even for scalar data types, assembly code makes no distinctions between signed or unsigned integers, between different types of pointers, or even between pointers and integers.</p>
<p>A key lesson to learn from this is that the program executed by the machine is simply a sequence of bytes encoding a series of instructions.</p>
<p>16bits: word<br>32bits: double words<br>64bits: quad words</p>
<p>16 general-purpose register storing 64-bit values. These registers are used to store integer data as well as pointers.</p>
<p>operand specifiers<br>操作数 most instruction have one or more operands specifying the source values to use in performing an operation and the destinaton location into which to place the result.</p>
<p>This technique takes advantage of the property that an instruction generating a 4-byte value with a register as the destination will fill the upper 4 bytes with zeros.</p>
<p>mismatch between instruction suffix and register ID</p>
<p>By way of background, a stack is a data structure whre values can be added or deleted, but only according to a “last-in, first-out” discipline.</p>
<p>operations are divided into four groups: load effective address, unary, binary, and shifts</p>
<ul>
<li>lea</li>
<li>unary 一元</li>
<li>binary 二元</li>
<li>shifts 移位</li>
</ul>
<p>leaq: instead of reading from the designated location, the instruction copies the effective address to the destination.</p>
<p>Note that when the second operand is a memory location, the processor must read the value from memory, perform the operation, and then write the result back to memory</p>
<p>CF (unsigned) t &lt; (unsigned) a Unsigned overflow<br>ZF (t == 0) Zero<br>SF (t &lt; 0) Negetive<br>OF (a &lt; 0 == b &lt; 0) &amp;&amp; (t &lt; 0 != a &lt; 0) Signed overflow</p>
<p>use contion code<br>1、we can set a single byte to 0 or 1 depending on some combination of the condition codes<br>2、we can conditionally jump to some other part of the progrma<br>3、we can conditionally transfer data.</p>
<p>In generating the object-code file, the assembler determines the addresses of all labeled instructions and encodes the jump targets (the addresses of the destination instructions) as part of the jump instructions.</p>
<p>not that jump instruction, but the next instruction of jump</p>
<p>Implementing Conditional Branches with Conditional Moves</p>
<p>why code based on conditional data transfers can outperform code based on conditional control transfers?</p>
<p>processors achieve high performance though pipelining,  — branch prediction logic</p>
<p>such a misprediction can incur a serious penalty,say,15-30clock cycles of wasted effort, causing a serious degradation of program performance</p>
<p>combination of conditional tests and jumps are used to implement the effect of loops.</p>
<p>switch allow an efficient implementation using a data structure called a jump table.</p>
<p>use of a jump table allows a very efficient way to implement a multiway branch</p>
<p>procedure involve:</p>
<ol>
<li>Passing control</li>
<li>Passing data.</li>
<li>Allocating and deallocating memory</li>
</ol>
<p>3.7.4 接下来应该读 Local Storage on the Stack</p>
<p>static:link</p>
<ol>
<li>找到符号。f 定位每一个函数f，能够定位到全局变量</li>
<li>symbol resolution</li>
<li>relocate</li>
</ol>
<p>文件elf<br>读头，寻道<br>连续的0/1串，起来就是</p>
<p>本质上就是视角上的不同。</p>
<ul>
<li><p>offset n<br>bytes</p>
</li>
<li><p>offset </p>
</li>
</ul>
<ul>
<li>offset 0</li>
</ul>
<ol>
<li>disk address 即 offset 0 但是无法读到大小？</li>
</ol>
<p>ELF : magic number</p>
<p>0-&gt; header -&gt; section header table</p>
<p>大家好，今天主要讨论静态链接。我将会从符号定位、符号解析、以及重定位三个方面来介绍静态链接。符号定位主要讨论的是Linux如何利用ELF文件格式来定位函数和全局变量。符号解析主要讨论多个可重定位文件链接到一起时如何解析符号，遇到多重定义符号怎么处理等内容。重定位，主要讨论多个可重定位文件链接成可执行程序时如何修正全局变量和函数调用的调用地址。OK，废话不多说。那我们就开始吧。</p>
<p>我们将会使用这个例子，贯穿整个静态链接的介绍。这个例子很简单，从csapp这本书摘抄出来的。首先有一个sum函数，计算一个数组的和。有一个全局的array数组，里面有1和2两个数据。一个main函数，调用sum函数，计算array数组的和。我们将这个文件进行预处理，编译，汇编最终生成了一个main.o的文件。在计算机中，一个文件其实就是字节序列，就是一些01串而已。那么如何从main.o这个01串中定位到array符号的呢？array中包含的数据到底是怎么存放在main.o这个文件中呢？</p>
<p>在Linux中像main.o这种目标文件是被组织成一种特殊的格式，叫做<br>Executabl 可执行<br>Linkable 可链接<br>Format 格式<br>简称ELF格式。<br>这张图就展现了一个elf文件格式的基本结构。<br>最开始的offset 0就是这个文件开始的地方。文件开始有一个elf header。之后还有一些.text 段.data 段等。最后还有一个Section header table，就叫做节头表吧。它是描述.text .data节的。这张图已经给了ELF文件大概的全景图，接下来会分别介绍其中的细节。首先介绍一个ELF Header。只有解析了elf header之后，才能根据其中的内容解析elf文件的其他部分。<br>(hexdump -C main.o 看一下整体的预览。)<br>对于ELF，首部的信息包括文件类型、机器类型等信息。在Linux读取ELF文件时，Linux将ELF Header从Byte翻译成内存中的数据结构：这个结构体就像这张PPT展示的一样。通常一个elf header中会存放这么些个东西，这个结构体是从/usr/bin/elf.h摘抄出来的。<br>每个项目列出来讲一讲。<br>e_indent<br>e_type<br>e_machine<br>e_version<br>e_entry<br>e_phoff<br>e_shoff<br>e_flags<br>e_ehsize<br>e_phentsize<br>e_phnum<br>e_shentsize<br>e_shnum<br>e_shstrndx<br>我们需要重点关注的是e_shoff, e_ensize e_shentsize e_shnum 变量。<br>// 应该需要吧elf.h 和hexdump之后的文件放上去。对照着讲。结合着讲。<br>起始位置的16个字节为magic number，在这之后偏移2+2+4+8+8=24个字节之后，为e_shoff，是section header table 的偏移量。数值为0x280 = 640，在这之后，对e_shoff偏移4字节是e_ehsize=0x40 表示elf header 的长度，即64个字节。我们可以看到整个elf_header 是64个字节，算得非常准确。最后是e_shnum = 0x0d = 13个section，字符串表的索引是12.好了我们，已经人眼识别，将整个elf header解析出来，接下来，我们用一个readelf工具，直接将header解析出来。</p>
<p>使用readelf -h main.o就可以将main.o的elf header解析出来了。划线的地方是需要重点关注的地方。使用readelf工具我们就可以更清楚的看到，section header table的偏移量，elf文件头的大小，每一个section header table的entry 大小。一个有多少个section header table。</p>
<p>OK，根据目前我们解析得到的内容，可以画出一个elf文件现在大概这样的。首先，有64Bytes的ELF header。在header中，根据e_shoff可以找到SHT的位置。根据e_shentnum我们可以知道一个有多少个SHT有多少个表项。根据e_shentsize可以知道SHT每个表项的大小。至此，我们可以计算出整个elf文件的大小。<br>e_shoff + e_shentnum * e_shentsize = 1472字节。</p>
<p>接下来把目光放到section header table中。这个结构体就是描述section header table的。<br>SHT描述了ELF中不同的节，包括数据节、代码节等。这些Section中的数据是由编译器生成的，按照section的组织写入到磁盘上的ELF文件中。SHT的每一项都可以被数据结构ELF64_Shdr所描述。<br>列出来，讲一讲。<br>其中包含，<br>sh_name 它是string table的index<br>sh_type: section type:<br>sh_flags: section flasg</p>
<p>// 需要结合代码展示一个hexdump的结构。</p>
<p>接下来我们就和解析ELF Header一样来人眼解析一个这个结构体。和解析ELF Header一样，对于SHT的每一个表项，按照上一页提到的数据结构逐个Byte解析，我们就可以得到.text对ELF文件的偏移：.sh_offset = 0x00000000040。回忆起我们先前得知ELF header的大小就是0x40，也即64Bytes，因此.text所处的位置正是Header之后。并且，它的大小为.sh_size - 0x0000000024</p>
<p>同样的，我们可以使用readelf作弊一下，可以将所有的section header table列出来。<br>值得一提的是，SHT中总存在[0]项目，它被视为未定义的符号所在Section，SHN_UNDEF，也就是0.</p>
<p>OK，现在elf header和section header table已经解析完毕了，大概可以画出这么一张图。<br>首先解析，elf_header, 我们得到section header table的位置，解析section header table之后我们可以得到各个section 在文件中的位置，以及它的大小。</p>
<p>解析来我们把目光放在.symbol section中。关于什么是符号的问题。<br>由模块m定义并能被其他模块引用的全局符号。<br>由其他模块定义并被模块m引用的全局符号。<br>只被模块m定义和引用的局部符号。</p>
<p>类似elf header 和 section header table。符号表也是由一个结构体来描述的。<br>st_name: 符号的名字，它是字符串表的索引。<br>st_info: 高四位是bind信息，低四位是type信息。<br>st_other: 保留信息<br>st_shndx: 该符号保存在某个section的index<br>st_value: 保存在某个section的offset<br>st_size: 符号的大小。</p>
<p>符号的绑定类型主要有：<br>STB_LOCAL<br>STB_GLOBAL<br>STB_WEAK</p>
<p>符号的type主要有：<br>NOTYPE<br>OBJECT<br>FUNC</p>
<p>同样的我们可以肉眼解析一个符号。例如，开头提到的array<br>st_name 是0x08，在字符串表偏移8个字节的位置，<br>bind是1： 为STB_GLOBAL<br>type是1：为STT_OBJECT<br>st_shndx: 是3 说明这个符号存储在.data节<br>st_value是0，说明array在.data节开始的位置。<br>st_size是0x08, 说明array符号大小为8个字节。</p>
<p>自此，我们可以知道array符号在elf文件位置的计算公式：<br>start：.data节在elf文件的偏移量+st_value<br>end: start+st_size<br>最终我们找到了array符号的存储位置。</p>
<p>同样的，也可以使用readelf工具作弊一下，使用readelf -s 命令就可以将符号表的信息列举出来。</p>
<p>首先解析，elf_header, 我们得到section header table的位置，解析section header table<br>我们可以得到.symtab的位置，解析.symtab就可以得到各个符号在文件中的存储位置。自此，终于可以成功定位符号了。因而我们解决了开头提到的符号定位问题。</p>
<p>接下来介绍符号解析问题。</p>
<p>如何design file？？？？ 疯狂搞链接，套娃。。。。之类的。很像MP4文件格式，<br>所有的文件格式都是按照树，按照图去组织的。</p>
<p>external intenal层</p>
<p>如何知道符号表在文件中的哪一个位置。</p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

        
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block home" lang="en">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2021/10/20/platform%E8%AE%BE%E5%A4%87%E9%A9%B1%E5%8A%A8/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="Z.J. Jiang">
      <meta itemprop="description" content="about the single image super-resolution and face hallucination">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="SRCNN">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          
            <a href="/2021/10/20/platform%E8%AE%BE%E5%A4%87%E9%A9%B1%E5%8A%A8/" class="post-title-link" itemprop="url">platform设备驱动</a>
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">Posted on</span>

              <time title="Created: 2021-10-20 22:39:00" itemprop="dateCreated datePublished" datetime="2021-10-20T22:39:00+08:00">2021-10-20</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">Edited on</span>
                <time title="Modified: 2022-01-01 20:22:57" itemprop="dateModified" datetime="2022-01-01T20:22:57+08:00">2022-01-01</time>
              </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h1 id="设备驱动模型"><a href="#设备驱动模型" class="headerlink" title="设备驱动模型"></a>设备驱动模型</h1><p>对于 Linux 这样一个成熟、庞大、复杂的操作系统，代码的重用性非常重要，否则的话就会在Linux内核中存在大量无意义的重复代码。当前Linux使用设备(device)，总线(bus)，驱动(driver)模型。Linux设备驱动模型如下图所示。<br><img src="/images/platform_driver.png" class="[Linux驱动模型示意图]" title="[14] [6] " alt="title text"><br>设备和驱动各司其职，设备干设备的活，驱动干驱动的活，总线将两者匹配起来。一个Linux设备和驱动都需要挂接在一种总线上，对于USB、I2C、SPI等有物理总线直接的设备来说，没有任何问题，但是在SoC中有些外设是没有总线这个概念的，但是又要使用总线、驱动和设备模型该怎么办呢？因此，Linux发明了一种虚拟总线，称为platform总线。相应的设备称为platform_device，而驱动称为platform_driver。</p>
<h1 id="platform-driver"><a href="#platform-driver" class="headerlink" title="platform_driver"></a>platform_driver</h1><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">platform_driver</span> &#123;</span></span><br><span class="line">    <span class="keyword">int</span> (*probe)(struct platform_device *);</span><br><span class="line">    <span class="keyword">int</span> (*<span class="built_in">remove</span>)(struct platform_device *);</span><br><span class="line">    <span class="keyword">void</span> (*<span class="built_in">shutdown</span>)(struct platform_device *);</span><br><span class="line">    <span class="keyword">int</span> (*suspend)(struct platform_device *, <span class="keyword">pm_message_t</span> state);</span><br><span class="line">    <span class="keyword">int</span> (*resume)(struct platform_device *);</span><br><span class="line">    <span class="class"><span class="keyword">struct</span> <span class="title">device_driver</span> <span class="title">driver</span>;</span></span><br><span class="line">    <span class="keyword">const</span> <span class="class"><span class="keyword">struct</span> <span class="title">platform_device_id</span> *<span class="title">id_table</span>;</span></span><br><span class="line">    <span class="keyword">bool</span> prevent_deferred_probe;</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>
<p>platform driver 结构体包含了probe remove。这个结构体用于注册驱动到platform总线。</p>
<h1 id="platform-device"><a href="#platform-device" class="headerlink" title="platform_device"></a>platform_device</h1><p>platform device的结构体如下所示。platform device结构体用于描述硬件信息，通常有一个名称用于和驱动绑定，还有一个资源列表，比如内存和中断<br><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">platform_device</span> &#123;</span></span><br><span class="line">    <span class="keyword">const</span> <span class="keyword">char</span>    *name;</span><br><span class="line">    <span class="keyword">int</span>        id;</span><br><span class="line">    <span class="keyword">bool</span>        id_auto;</span><br><span class="line">    <span class="class"><span class="keyword">struct</span> <span class="title">device</span>    <span class="title">dev</span>;</span></span><br><span class="line">    u64        platform_dma_mask;</span><br><span class="line">    <span class="class"><span class="keyword">struct</span> <span class="title">device_dma_parameters</span> <span class="title">dma_parms</span>;</span></span><br><span class="line">    u32        num_resources;</span><br><span class="line">    <span class="class"><span class="keyword">struct</span> <span class="title">resource</span>    *<span class="title">resource</span>;</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">const</span> <span class="class"><span class="keyword">struct</span> <span class="title">platform_device_id</span>    *<span class="title">id_entry</span>;</span></span><br><span class="line">    <span class="keyword">char</span> *driver_override; <span class="comment">/* Driver name to force a match */</span></span><br><span class="line"></span><br><span class="line">    <span class="comment">/* MFD cell pointer */</span></span><br><span class="line">    <span class="class"><span class="keyword">struct</span> <span class="title">mfd_cell</span> *<span class="title">mfd_cell</span>;</span></span><br><span class="line"></span><br><span class="line">    <span class="comment">/* arch specific additions */</span></span><br><span class="line">    <span class="class"><span class="keyword">struct</span> <span class="title">pdev_archdata</span>    <span class="title">archdata</span>;</span></span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure></p>
<p>platform设备的资源由resource结构体描述。flags可以是IORESOURCE_MEM、IORESOURCE_IRQ类型。当flags是IORESOURCE_MEM时，start、end表示该platform_device占据的内存的起始地址和结束地址；当flags是IORESOURCE_IRQ时，表示该platform_device使用的中断号的开始值和结束值，如果使用了1个中断号，开始和结束值相同。<br><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">resource</span> &#123;</span></span><br><span class="line">    <span class="keyword">resource_size_t</span> start;  <span class="comment">// 表示资源的起始值，           </span></span><br><span class="line">    <span class="keyword">resource_size_t</span> <span class="built_in">end</span>;    <span class="comment">// 表示资源的最后一个字节的地址</span></span><br><span class="line">    <span class="keyword">const</span> <span class="keyword">char</span> *name;</span><br><span class="line">    <span class="keyword">unsigned</span> <span class="keyword">long</span> flags; <span class="comment">//资源的类型</span></span><br><span class="line">    <span class="class"><span class="keyword">struct</span> <span class="title">resource</span> *<span class="title">parent</span>, *<span class="title">sibling</span>, *<span class="title">child</span>;</span></span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure></p>
<h1 id="platform-bus-type"><a href="#platform-bus-type" class="headerlink" title="platform bus type"></a>platform bus type</h1><p>系统为platform总线定义了一个bus_type的实例platform_bus_type。需要重点关注<code>platform_match</code>函数，该函数就是驱动和设备的匹配函数。<br><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">bus_type</span> <span class="title">platform_bus_type</span> = &#123;</span></span><br><span class="line">    .name        = <span class="string">"platform"</span>,</span><br><span class="line">    .dev_groups    = platform_dev_groups,</span><br><span class="line">    .match        = platform_match,</span><br><span class="line">    .uevent        = platform_uevent,</span><br><span class="line">    .dma_configure    = platform_dma_configure,</span><br><span class="line">    .pm        = &amp;platform_dev_pm_ops,</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure></p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">static</span> <span class="keyword">int</span> <span class="title">platform_match</span><span class="params">(struct device *dev, struct device_driver *drv)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="class"><span class="keyword">struct</span> <span class="title">platform_device</span> *<span class="title">pdev</span> = <span class="title">to_platform_device</span>(<span class="title">dev</span>);</span></span><br><span class="line">    <span class="class"><span class="keyword">struct</span> <span class="title">platform_driver</span> *<span class="title">pdrv</span> = <span class="title">to_platform_driver</span>(<span class="title">drv</span>);</span></span><br><span class="line"></span><br><span class="line">    <span class="comment">/* When driver_override is set, only bind to the matching driver */</span></span><br><span class="line">    <span class="keyword">if</span> (pdev-&gt;driver_override)</span><br><span class="line">        <span class="keyword">return</span> !<span class="built_in">strcmp</span>(pdev-&gt;driver_override, drv-&gt;name);</span><br><span class="line"></span><br><span class="line">    <span class="comment">/* Attempt an OF style match first */</span></span><br><span class="line">    <span class="keyword">if</span> (of_driver_match_device(dev, drv))</span><br><span class="line">        <span class="keyword">return</span> <span class="number">1</span>;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/* Then try ACPI style match */</span></span><br><span class="line">    <span class="keyword">if</span> (acpi_driver_match_device(dev, drv))</span><br><span class="line">        <span class="keyword">return</span> <span class="number">1</span>;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/* Then try to match against the id table */</span></span><br><span class="line">    <span class="keyword">if</span> (pdrv-&gt;id_table)</span><br><span class="line">        <span class="keyword">return</span> platform_match_id(pdrv-&gt;id_table, pdev) != <span class="literal">NULL</span>;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/* fall-back to driver name match */</span></span><br><span class="line">    <span class="keyword">return</span> (<span class="built_in">strcmp</span>(pdev-&gt;name, drv-&gt;name) == <span class="number">0</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>可以看出platform_match有四种匹配模式。一种是基于设备树风格的匹配；二是基于ACPI风格的匹配；三是ID表的匹配，platform_driver有一个id_table的变量；四是匹配platform_device设备名和驱动名。</p>
<h1 id="注册platform驱动"><a href="#注册platform驱动" class="headerlink" title="注册platform驱动"></a>注册platform驱动</h1><h2 id="注册设备"><a href="#注册设备" class="headerlink" title="注册设备"></a>注册设备</h2><p>platform_device_register函数可以注册设备.</p>
<h2 id="注册驱动"><a href="#注册驱动" class="headerlink" title="注册驱动"></a>注册驱动</h2><p>platform_driver_register函数可以注册驱动。</p>
<h1 id="match和probe函数的调用时机"><a href="#match和probe函数的调用时机" class="headerlink" title="match和probe函数的调用时机"></a>match和probe函数的调用时机</h1><p>下面的函数调用链展示了，设备和驱动何时通过match函数绑定到一起，以及何时执行驱动的probe函数。在调用<code>platform_driver_register</code>注册驱动时，会调用总线上的match函数，即platform_bus_type.match函数将驱动和设备绑定到一起，驱动和设备绑定成功之后，就会执行驱动的probe函数。<br><figure class="highlight xl"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">platform_driver_register</span><br><span class="line">    __platform_driver_register</span><br><span class="line">        driver_register <span class="comment">// 注册驱动</span></span><br><span class="line">            bus_add_driver <span class="comment">// 将驱动添加到总线上</span></span><br><span class="line">                driver_attach <span class="comment">// 将驱动和设备绑定到一起</span></span><br><span class="line">                    __driver_attach</span><br><span class="line">                        driver_match_device</span><br><span class="line">                            <span class="function"><span class="title">drv</span>-&gt;</span><span class="function"><span class="title">bus</span>-&gt;</span>match <span class="comment">// 最后调用总线上的match函数，即platform_bus_type.match函数，如上所述，共有四种match方式</span></span><br><span class="line"></span><br><span class="line">                        device_driver_attach <span class="comment">// 将特定的驱动和设备关联到一起</span></span><br><span class="line">                            driver_probe_device <span class="comment">// 驱动检测到设备后调用probe函数。</span></span><br><span class="line">                                really_probe</span><br><span class="line">                                    <span class="function"><span class="title">drv</span>-&gt;</span>probe <span class="comment">// 调用驱动的probe函数</span></span><br></pre></td></tr></table></figure></p>
<h1 id="Example"><a href="#Example" class="headerlink" title="Example"></a>Example</h1><p>driver.c<br><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;linux/module.h&gt;    /* Needed by all modules */</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;linux/kernel.h&gt;    /* Needed for KERN_INFO */</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;linux/platform_device.h&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;linux/init.h&gt;        /* Needed for the macros */</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> DRIVER_AUTHOR <span class="meta-string">"Jiang Zijin"</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> DRIVER_DESC   <span class="meta-string">"A platform driver test"</span></span></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">static</span> <span class="keyword">int</span> <span class="title">pfd_driver_probe</span><span class="params">(struct platform_device *pdev)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    printk(KERN_INFO <span class="string">"platform driver probe\n"</span>);</span><br><span class="line">    <span class="comment">/* do something */</span></span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">static</span> <span class="keyword">int</span> <span class="title">pfd_driver_remove</span><span class="params">(struct platform_device *pdev)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="comment">/* do something */</span></span><br><span class="line">    printk(KERN_INFO <span class="string">"platform driver remove\n"</span>);</span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">static</span> <span class="class"><span class="keyword">struct</span> <span class="title">platform_driver</span> <span class="title">pfd_driver</span> = &#123;</span></span><br><span class="line">    .driver = &#123;</span><br><span class="line">        .name    = <span class="string">"pfd_driver_test"</span>,</span><br><span class="line">        .owner = THIS_MODULE,</span><br><span class="line">    &#125;,</span><br><span class="line">    .probe        = pfd_driver_probe,</span><br><span class="line">    .<span class="built_in">remove</span>        = pfd_driver_remove,</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line"><span class="comment">/* module_driver(__platform_driver, platform_driver_register, \</span></span><br><span class="line"><span class="comment">            platform_driver_unregister) */</span></span><br><span class="line"><span class="comment">/* 调用platform_driver_register注册驱动 */</span></span><br><span class="line">module_platform_driver(pfd_driver);</span><br><span class="line"></span><br><span class="line">MODULE_LICENSE(<span class="string">"GPL"</span>);</span><br><span class="line">MODULE_AUTHOR(DRIVER_AUTHOR);</span><br><span class="line">MODULE_DESCRIPTION(DRIVER_DESC);</span><br></pre></td></tr></table></figure></p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;linux/module.h&gt;    /* Needed by all modules */</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;linux/kernel.h&gt;    /* Needed for KERN_INFO */</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;linux/platform_device.h&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;linux/init.h&gt;        /* Needed for the macros */</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> DRIVER_AUTHOR <span class="meta-string">"Jiang Zijin"</span></span></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">static</span> <span class="keyword">void</span> <span class="title">test_pfd_release</span><span class="params">(struct device *dev)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    <span class="keyword">return</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">static</span> <span class="class"><span class="keyword">struct</span> <span class="title">platform_device</span> <span class="title">test_pdev</span> = </span></span><br><span class="line"><span class="class">&#123;</span></span><br><span class="line">    .name = <span class="string">"pfd_driver_test"</span>,</span><br><span class="line">    .id = <span class="number">-1</span>,</span><br><span class="line">    .dev.<span class="built_in">release</span> = test_pfd_release,</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line"><span class="keyword">static</span> <span class="keyword">int</span> __<span class="function">init <span class="title">test_pdev_init</span><span class="params">(<span class="keyword">void</span>)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    printk(KERN_INFO <span class="string">"platform device init\n"</span>);</span><br><span class="line">    <span class="keyword">return</span> platform_device_register(&amp;test_pdev);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">static</span> <span class="keyword">void</span> __<span class="function"><span class="built_in">exit</span> <span class="title">test_pdev_exit</span><span class="params">(<span class="keyword">void</span>)</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line">    printk(KERN_INFO <span class="string">"platform device exit\n"</span>);</span><br><span class="line">    platform_device_unregister(&amp;test_pdev);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">module_init(test_pdev_init);</span><br><span class="line">module_exit(test_pdev_exit)</span><br><span class="line"></span><br><span class="line">MODULE_LICENSE(<span class="string">"GPL"</span>);</span><br><span class="line">MODULE_AUTHOR(DRIVER_AUTHOR);</span><br></pre></td></tr></table></figure>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">KVERS = $(shell uname -r)</span><br><span class="line"></span><br><span class="line"># Kernel modules</span><br><span class="line">obj-m += pfd_driver.o pfd_device.o</span><br><span class="line"></span><br><span class="line"># Specify flags <span class="keyword">for</span> the <span class="keyword">module</span> compilation.</span><br><span class="line">EXTRA_CFLAGS=-g -O0</span><br><span class="line"></span><br><span class="line">build: kernel_modules</span><br><span class="line"></span><br><span class="line">kernel_modules:</span><br><span class="line">4make -C /lib/modules/$(KVERS)/build M=$(CURDIR) modules</span><br><span class="line"></span><br><span class="line">clean:</span><br><span class="line">4make -C /lib/modules/$(KVERS)/build M=$(CURDIR) clean</span><br></pre></td></tr></table></figure>
<p>执行make即可成功编译出<code>pfd_driver.ko</code>和<code>pfd_device.ko</code>两个内核文件。可使用insmode加载这两个内核文件。<br><figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-tag">insmod</span> <span class="selector-tag">pfd_device</span><span class="selector-class">.ko</span></span><br><span class="line"><span class="selector-tag">insmod</span> <span class="selector-tag">pfd_driver</span><span class="selector-class">.ko</span></span><br><span class="line"><span class="selector-attr">[  556.856482]</span> <span class="selector-tag">platform</span> <span class="selector-tag">device</span> <span class="selector-tag">init</span></span><br><span class="line"><span class="selector-attr">[  561.823973]</span> <span class="selector-tag">platform</span> <span class="selector-tag">driver</span> <span class="selector-tag">probe</span></span><br></pre></td></tr></table></figure><br>加载后使用<code>demsg</code>打印内核信息即可看到<code>platform device init</code>和<code>platform driver probe</code>的打印。这说明platform设备和驱动绑定到一起了，绑定成功之后就执行驱动的probe函数。</p>
<p>ok，这个例子似乎有点简单，加点资源进去。加上一点内存和中断号的资源，并在驱动的probe函数中使用。在驱动中很容易就可以使用到这些资源了。</p>
<p>TODO： 把相应代码加上。</p>
<p>[  432.948791] platform device init<br>[  437.752513] platform driver probe<br>[  437.752517] mem start addr = 12340000<br>[  437.752520] irq num = 100</p>
<h1 id="设备树"><a href="#设备树" class="headerlink" title="设备树"></a>设备树</h1><p>从上面的例子可以发现，platform device可能除了一些resource资源不一样外，其他部分大差不差的。如果每来一个设备都需要写一个xxx_device.c，那么内核代码就会很臃肿。因此引入了描述硬件的数据结构—设备树。采用设备树之后，许多硬件的细节可以直接通过它传递给Linux，而不再需要在内核中进行大量的冗余编码。</p>
<p>本文不对设备树进行过多介绍，仅展示使用设备树之后的便利性。<br>上述的例子中，我们可以把device相关的代码改用dts实现，只需要在dts中正确配置即可，无需在写那么多的设备代码了。在设备和驱动match过程中，通过相应的dts的接口match上。</p>
<h1 id="dts方式的match"><a href="#dts方式的match" class="headerlink" title="dts方式的match"></a>dts方式的match</h1><figure class="highlight sqf"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">of_driver_match_device <span class="comment">// 驱动的of_match_table是否match上了相应的设备</span></span><br><span class="line">    of_match_device</span><br><span class="line">        of_match_node</span><br><span class="line">            <span class="variable">__of_match_node</span></span><br><span class="line">                <span class="variable">__of_device_is_compatible</span></span><br><span class="line">                    <span class="variable">__of_find_property</span> <span class="comment">// prop = __of_find_property(device, "compatible", NULL); 最终是利用dts的"compatible"来匹配的，即设备树加载之后，内核会自动把设备树节点转换成platform_device这种格式，同时把名字放到of_node这个地方。</span></span><br></pre></td></tr></table></figure>
<h1 id="改写example"><a href="#改写example" class="headerlink" title="改写example"></a>改写example</h1><p>设备树的详细内容这里就不再展开介绍了，下面将上述例子的device部分改写成设备树实现，展示一下使用设备树的便利性。<br>TODO: 把代码贴上去。直接该内核的。 已完成，放到公司内网中了。<br>参考：<br>《Linux设备驱动开发详解》<br><a href="https://zhuanlan.zhihu.com/p/134180200" target="_blank" rel="noopener">https://zhuanlan.zhihu.com/p/134180200</a><br><a href="https://biscuitos.github.io/blog/DTS/#:~:text=DTS%20%E6%98%AF%E4%B8%BA%20Linux%20%E6%8F%90%E4%BE%9B%E4%B8%80%E7%A7%8D%E7%A1%AC%E4%BB%B6%E4%BF%A1%E6%81%AF%E7%9A%84%E6%8F%8F%E8%BF%B0%E6%96%B9%E6%B3%95%EF%BC%8C%E4%BB%A5%E6%AD%A4%E4%BB%A3%E6%9B%BF%E6%BA%90%E7%A0%81%E4%B8%AD%E7%9A%84%20%E7%A1%AC%E4%BB%B6%E7%BC%96%E7%A0%81%20%28hard%20code%29%E3%80%82%20DTS,%28OF%29.%20%E5%9C%A8%20Linux%202.6%20%E4%B8%AD%EF%BC%8C%20ARM%20%E6%9E%B6%E6%9E%84%E7%9A%84%E6%9D%BF%E7%BA%A7%E7%A1%AC%E4%BB%B6%E7%BB%86%E8%8A%82%E8%BF%87%E5%A4%9A%E7%9A%84%E8%A2%AB%E7%A1%AC%E7%BC%96%E7%A0%81%E5%9C%A8%20arch%2Farm%2Fplat-xxx" target="_blank" rel="noopener">https://biscuitos.github.io/blog/DTS/#:~:text=DTS%20%E6%98%AF%E4%B8%BA%20Linux%20%E6%8F%90%E4%BE%9B%E4%B8%80%E7%A7%8D%E7%A1%AC%E4%BB%B6%E4%BF%A1%E6%81%AF%E7%9A%84%E6%8F%8F%E8%BF%B0%E6%96%B9%E6%B3%95%EF%BC%8C%E4%BB%A5%E6%AD%A4%E4%BB%A3%E6%9B%BF%E6%BA%90%E7%A0%81%E4%B8%AD%E7%9A%84%20%E7%A1%AC%E4%BB%B6%E7%BC%96%E7%A0%81%20%28hard%20code%29%E3%80%82%20DTS,%28OF%29.%20%E5%9C%A8%20Linux%202.6%20%E4%B8%AD%EF%BC%8C%20ARM%20%E6%9E%B6%E6%9E%84%E7%9A%84%E6%9D%BF%E7%BA%A7%E7%A1%AC%E4%BB%B6%E7%BB%86%E8%8A%82%E8%BF%87%E5%A4%9A%E7%9A%84%E8%A2%AB%E7%A1%AC%E7%BC%96%E7%A0%81%E5%9C%A8%20arch%2Farm%2Fplat-xxx</a></p>
<p>platform驱动转成dts<br><a href="https://blog.csdn.net/zqixiao_09/article/details/50889458" target="_blank" rel="noopener">https://blog.csdn.net/zqixiao_09/article/details/50889458</a></p>
<p>source code:<br><a href="https://gitee.com/jzijin/linux_driver" target="_blank" rel="noopener">https://gitee.com/jzijin/linux_driver</a></p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

        
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block home" lang="en">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2021/09/07/%E7%94%9F%E6%B6%AF%E8%A7%84%E5%88%92-%E7%92%80%E7%92%A8%E4%BA%BA%E7%94%9F/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="Z.J. Jiang">
      <meta itemprop="description" content="about the single image super-resolution and face hallucination">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="SRCNN">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          
            <a href="/2021/09/07/%E7%94%9F%E6%B6%AF%E8%A7%84%E5%88%92-%E7%92%80%E7%92%A8%E4%BA%BA%E7%94%9F/" class="post-title-link" itemprop="url">生涯规划 璀璨人生</a>
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">Posted on</span>

              <time title="Created: 2021-09-07 23:09:08" itemprop="dateCreated datePublished" datetime="2021-09-07T23:09:08+08:00">2021-09-07</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">Edited on</span>
                <time title="Modified: 2021-09-09 00:18:59" itemprop="dateModified" datetime="2021-09-09T00:18:59+08:00">2021-09-09</time>
              </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <ul>
<li>走出家门，不要坐井观天。<br>幸存者偏差？</li>
<li>想法改变命运？态度决定成功？</li>
<li>梦想清单？？？ 作业<br>只做职业规划？？？<br>四大危机？<br>健康危机、教育危机、婚姻家庭危机、有工作没保障</li>
</ul>
<p>人生规划<br>要什么？<br>混：日子好比流水。。。<br>忙盲茫 三个字过一生。</p>
<p>学什么？你不吃我最佩服？？？？不认同。<br>检讨自己是成功的开始，检讨别人是失败的开始？</p>
<p>做什么？</p>
<p>得什么？</p>

      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

        
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block home" lang="en">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2021/09/01/%E9%AB%98%E6%95%88%E8%83%BD%E4%BA%BA%E5%A3%AB%E7%9A%84%E4%B8%83%E4%B8%AA%E4%B9%A0%E6%83%AF/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="Z.J. Jiang">
      <meta itemprop="description" content="about the single image super-resolution and face hallucination">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="SRCNN">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          
            <a href="/2021/09/01/%E9%AB%98%E6%95%88%E8%83%BD%E4%BA%BA%E5%A3%AB%E7%9A%84%E4%B8%83%E4%B8%AA%E4%B9%A0%E6%83%AF/" class="post-title-link" itemprop="url">高效能人士的七个习惯</a>
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">Posted on</span>

              <time title="Created: 2021-09-01 23:04:17" itemprop="dateCreated datePublished" datetime="2021-09-01T23:04:17+08:00">2021-09-01</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">Edited on</span>
                <time title="Modified: 2021-10-20 22:31:30" itemprop="dateModified" datetime="2021-10-20T22:31:30+08:00">2021-10-20</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">In</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/humanities/" itemprop="url" rel="index">
                    <span itemprop="name">humanities</span>
                  </a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h1 id="序言"><a href="#序言" class="headerlink" title="序言"></a>序言</h1><p>近期陷入迷茫中，不知道工作有什么意思，生活总是很无聊。总是在思考终极的哲学问题，我想我不能在这样下去了，这样下去不得疯了？因此，来寻找毒鸡汤了，又拿出了很久之前读过的《高效能人士的七个习惯》来重新翻阅寻找一下力量了。</p>
<h1 id="chapter-1-由内而外全面造就自己"><a href="#chapter-1-由内而外全面造就自己" class="headerlink" title="chapter 1 由内而外全面造就自己"></a>chapter 1 由内而外全面造就自己</h1><blockquote><p>没有正确的生活，就没有真正卓越的人生。</p>
<footer><strong>David Starr Jordan</strong></footer></blockquote>
<p>要改变现状，首先要改变自己；要改变自己，先要改变我们对问题的看法。</p>
<h2 id="品德与个人魅力孰重"><a href="#品德与个人魅力孰重" class="headerlink" title="品德与个人魅力孰重"></a>品德与个人魅力孰重</h2><p>不要总是用”术”，更多的真诚待人。</p>
<h2 id="光有技巧还不够"><a href="#光有技巧还不够" class="headerlink" title="光有技巧还不够"></a>光有技巧还不够</h2><p>技巧不是最重要的，不要老是用技巧。过多使用技巧有时会适得其反，真诚待人才是王道。只有品德才是交流中最伶俐的“口齿”，正如美国诗人爱默生所说：“大声喧哗反而难以入耳”。人性可善可恶，冥冥中影响着我们的一生，而且总是如实反映出真正的自我，那是伪装不来的。</p>
<h2 id="思维方式的力量"><a href="#思维方式的力量" class="headerlink" title="思维方式的力量"></a>思维方式的力量</h2><p>我们总是用思维方式绘制的地图诠释所有的经验，从来都不怀疑地图的正确性，甚至意识不到它们的存在。我们理所当然地假定自己的所见所闻就是真是的世界。<br>我们总以为只有自己清楚而客观地看到了事物的本质，但这个实验却让我们开始认识到，别人的观点虽然又差异，但也是清楚而客观的。“立场决定观点。”</p>
<h2 id="思维转换力量"><a href="#思维转换力量" class="headerlink" title="思维转换力量"></a>思维转换力量</h2><p>“一棵邪恶的大树，砍它枝叶千斧，不如砍它根基一斧。”行为和态度就是枝叶，思维方式就是根基，抓住根本才能让生活出现实质性的进展。</p>
<h2 id="身体力行"><a href="#身体力行" class="headerlink" title="身体力行"></a>身体力行</h2><p>思维转换的力量也正是定式改变必需的力量，无论这种转变是立即发生的，还是经过计划缓慢进行的。</p>
<h2 id="已原则为中心的思维方式"><a href="#已原则为中心的思维方式" class="headerlink" title="已原则为中心的思维方式"></a>已原则为中心的思维方式</h2><p>现代人的精神危机：<br>我真正缺少的东西就是要在我内心弄清楚：我到底要做什么事情？问题在于，要找到一个对我来说确实的真理，找到一个我能够为此而生、为此而死的新年。</p>
<p>一个人能承受多少真相，是对他的精神强度的考验。</p>
<h2 id="成长和改变的原则"><a href="#成长和改变的原则" class="headerlink" title="成长和改变的原则"></a>成长和改变的原则</h2><p>如果学生不肯发问，不肯暴露自己的无知，不肯让老师知道他的真正水平，那么绝对学不到东西，也就不可能有长进。梭罗曾今说过：“如果我们时时忙着展现自己的知识，将何从忆起成长所需的无知？”</p>
<p>只有真正经历过拥有，才会真正懂得分享。</p>
<h2 id="症状在于治标不治本"><a href="#症状在于治标不治本" class="headerlink" title="症状在于治标不治本"></a>症状在于治标不治本</h2><h2 id="新的思想水平"><a href="#新的思想水平" class="headerlink" title="新的思想水平"></a>新的思想水平</h2><p>以原则为中心，以品德为基础，要求“由内而外”地实现个人效能和人际效能。<br>由内而外的观点认为个人领域的呈贡必须先于公众领域的成功；只有先信守对自己的承诺，才能信守对他人的承诺。<br>我们必不可停止探索，而一切探索的尽头，就是重回起点，并对起点有如初见般的了解。</p>
<h1 id="七个习惯概论"><a href="#七个习惯概论" class="headerlink" title="七个习惯概论"></a>七个习惯概论</h1><blockquote><p>人的行为总是一再重复。因此卓越不是一时的行为，而是习惯。</p>
<footer><strong>亚里士多德</strong></footer></blockquote>
<h2 id="“习惯”的定义"><a href="#“习惯”的定义" class="headerlink" title="“习惯”的定义"></a>“习惯”的定义</h2><p>习惯定义为“知识”、“技巧”、与“意愿”相互交织的结果。<br>改变习惯是一个痛苦的过程，因为有了更高的目标才能激发改变，面向未来牺牲当下的意愿才能促进改变。但是这又是幸福的源泉，是生活的目标和规划。从这个角度来说，幸福就是我们经过一番努力与牺牲得到的果实。</p>
<h2 id="成熟模式图"><a href="#成熟模式图" class="headerlink" title="成熟模式图"></a>成熟模式图</h2><ul>
<li>依赖期 以“你”为核心 — 你照顾我；你为我的得失成败负责</li>
<li>独立期 以“我”为核心 — 我可以做到；我可以负责；我可以靠自己；我有权选择。</li>
<li>互赖期 以“我们”为核心 — 我们可以做到；我们可以合作；我们可以融合彼此的智慧和能力，共创前程。</li>
</ul>
<h2 id="“效能”的定义"><a href="#“效能”的定义" class="headerlink" title="“效能”的定义"></a>“效能”的定义</h2><p>“产出/产能”平衡。伊索寓言中的鹅生金蛋的故事。效能在于产出和产能的平衡。P代表希望获得的产出，即金蛋；PC代表产能，即生产金蛋的资产或能力。</p>
<h2 id="三类资产"><a href="#三类资产" class="headerlink" title="三类资产"></a>三类资产</h2><ul>
<li>物质资产</li>
<li>金融资本</li>
<li>人力资本</li>
</ul>
<p>急功近利常常会毁掉宝贵的物质资产。保持产出与产能的平衡会帮助你更有效地利用物质资产。写程序应该也是这样吧。慢就是快，欲速则不达，read deeply！！</p>
<p>我们最宝贵的金融资本就是赚钱的能力。如果不能持续投资以增进自己的产能，眼光就会受到限制，只能在现有的职位上踏步，每天忙忙碌碌。</p>
<h2 id="你将获得什么？"><a href="#你将获得什么？" class="headerlink" title="你将获得什么？"></a>你将获得什么？</h2><p>对自己的改变要有耐心，因为自我成长是神圣的，同时也是脆弱的，是人生中最大的投资。虽然这需要长时间下功夫，但是必定会有鼓舞人心的可喜成效。</p>
<p>得之太易者必不受珍惜。唯有付出代价，万物始有价值。上苍深知如何为其产品制订合理的价格。</p>
<h2 id="七个习惯的简要定义"><a href="#七个习惯的简要定义" class="headerlink" title="七个习惯的简要定义"></a>七个习惯的简要定义</h2><ol>
<li>积极主动</li>
<li>以终为始</li>
<li>要事第一</li>
<li>双赢思维</li>
<li>知彼解己</li>
<li>统合综效</li>
<li>不断更新</li>
</ol>
<h1 id="chapter-2-习惯一-积极主动-—-个人愿景原则"><a href="#chapter-2-习惯一-积极主动-—-个人愿景原则" class="headerlink" title="chapter 2 习惯一 积极主动 — 个人愿景原则"></a>chapter 2 习惯一 积极主动 — 个人愿景原则</h1><p>人性的本质是主动而非被动的，人类不仅能针对特定环境选择回应方式，更能主动创造有利的环境。采取主动不等于胆大妄为、惹是生非或滋事挑衅，而是要充分认识到自己有责任创造条件。</p>
<h2 id="社会之镜"><a href="#社会之镜" class="headerlink" title="社会之镜"></a>社会之镜</h2><p>解释人性的三种决定论</p>
<ul>
<li>基因决定论</li>
<li>心理决定论</li>
<li>环境决定论</li>
</ul>
<h2 id="刺激和回应之间选择的自由"><a href="#刺激和回应之间选择的自由" class="headerlink" title="刺激和回应之间选择的自由"></a>刺激和回应之间选择的自由</h2><p>人性最根本的原则，即在刺激与回应之间，人有选择的自由。选择的自由包括人类特有的四种天赋。自我意识，想象力，良知，独立意志。</p>
<h2 id="“积极主动”的定义"><a href="#“积极主动”的定义" class="headerlink" title="“积极主动”的定义"></a>“积极主动”的定义</h2><p>积极主动不仅指行事的态度，还意味着人一定要对自己的人生负责。个人行为取决于自身的抉择，而不是外在的环境，人类应该有营造有利的外在环境的积极性和责任感。<br>伤害我们的并非悲惨遭遇本身，而是我们对于悲惨遭遇的回应。</p>
<h2 id="采取主动"><a href="#采取主动" class="headerlink" title="采取主动"></a>采取主动</h2><h2 id="变被动为主动"><a href="#变被动为主动" class="headerlink" title="变被动为主动"></a>变被动为主动</h2><p>积极行动不同于积极思考。我们不但需要面对现实，还要面对未来。但真正的现实是，我们有能力以积极态度应对现状和未来，逃避这一现实，就只能被动地让环境和条件决定一切。</p>
<h2 id="聆听自己的声音"><a href="#聆听自己的声音" class="headerlink" title="聆听自己的声音"></a>聆听自己的声音</h2><p>在所有进步的社会中，爱都是代表动作，但消极被动的人却把爱当作一种感觉。</p>
<h2 id="关注圈和影响圈"><a href="#关注圈和影响圈" class="headerlink" title="关注圈和影响圈"></a>关注圈和影响圈</h2><p>每个人都有格外关注的问题，比如健康，子女，事业，工作，股票等。这些被归入 关注圈 中，以区别与自己没有兴趣或不愿理会的事物。</p>
<p>关注圈内的事物，有些可以被掌控，有些则超出个人能力范围，前者可以被形成一个较小的“影响圈”<br>消极被动的人全神贯注于“关注圈”，而积极主动的人虽然更看重自己的影响力，但他们的关注圈往往不小于影响圈子。</p>
<h2 id="直接控制、间接控制和无法控制"><a href="#直接控制、间接控制和无法控制" class="headerlink" title="直接控制、间接控制和无法控制"></a>直接控制、间接控制和无法控制</h2><ul>
<li>可直接控制问题：可以通过培养正确习惯来解决，这显然在影响圈范围内。</li>
<li>可间接控制的问题：可以通过改进施加影响的方法来解决，例如采取移情方式而不是针锋相对，以身作则而不是口头游说。</li>
<li>无法控制的问题：我们要做的就是改变面部曲线，以微笑、真诚与平和来接收现实。</li>
</ul>
<h2 id="扩大影响圈"><a href="#扩大影响圈" class="headerlink" title="扩大影响圈"></a>扩大影响圈</h2><p>有人误以为“积极主动”就是胆大妄为、滋事挑衅或目中无人，其实不然，及积极处世者只是更为机敏，更重视价值观，能够切乎实际，并掌握问题的症结所在。</p>
<h2 id="“如果”和“我可以”"><a href="#“如果”和“我可以”" class="headerlink" title="“如果”和“我可以”"></a>“如果”和“我可以”</h2><h2 id="硬币的另一面—应对错误的选择"><a href="#硬币的另一面—应对错误的选择" class="headerlink" title="硬币的另一面—应对错误的选择"></a>硬币的另一面—应对错误的选择</h2><p>对于已经无法挽回的错误，积极主动的人不是悔恨不已，而是承认往日错误已属关注圈的事实，那是人力无法企及的范畴，既不能从头来过，也不能改变必然后果。</p>
<h2 id="做出承诺，信守诺言"><a href="#做出承诺，信守诺言" class="headerlink" title="做出承诺，信守诺言"></a>做出承诺，信守诺言</h2><p>影响圈的核心就是做出承诺与信守诺言的能力。积极主动的本质和最清晰的表现就是对自己或别人有所承诺，然后从不食言。</p>
<h1 id="chapter-2-以终为始-—-自我领导原则"><a href="#chapter-2-以终为始-—-自我领导原则" class="headerlink" title="chapter 2 以终为始 — 自我领导原则"></a>chapter 2 以终为始 — 自我领导原则</h1><p>太多人成功之后，反而感到空虚；得到名利之后，却发现牺牲了更宝贵的东西。因此，我们务必固守真正重要的愿景，然后勇往直前坚持到底，是生活充满意义。</p>
<blockquote><p>和内在力量相比，身外之物显得微不足道。</p>
<footer><strong>David Starr Jordan</strong></footer></blockquote>
<h2 id="“以终为始”的定义"><a href="#“以终为始”的定义" class="headerlink" title="“以终为始”的定义"></a>“以终为始”的定义</h2><p>从现在开始，以你的人生目标作为衡量一切的标准，你的一言一行，一举一动，无论发生在何时，都必须遵守这一原则，即由个人最重视的期许或价值观来决定一切。以终为始说明在做任何事之前，都要先认清方向。</p>
<h2 id="任何事物都需要两次创造"><a href="#任何事物都需要两次创造" class="headerlink" title="任何事物都需要两次创造"></a>任何事物都需要两次创造</h2><p>“以终为始”的一个原则基础是“任何事都是两次创造而成”。我们做任何事都是现在头脑中构思，即智力上的或第一次的创造(Mental/First Creation)，然后付诸实践，即体力上的或第二次创造(Physical/Second Creation)</p>
<h2 id="主动设计还是被动接受"><a href="#主动设计还是被动接受" class="headerlink" title="主动设计还是被动接受"></a>主动设计还是被动接受</h2><p>自我意识、良知和想象力这些人类的独特天赋让我们能审视各种第一次的创造，并掌握自己的那一部分，即自己撰写自己的剧本。换句话说，习惯一谈的是“你是创造者”，习惯二谈的是“第一次创造”。</p>
<h2 id="领导与管理：两次创造"><a href="#领导与管理：两次创造" class="headerlink" title="领导与管理：两次创造"></a>领导与管理：两次创造</h2><p>领导和管理就好比思想与行为。管理是正确地做事，领导则是做正确的是。管理是有效地顺着成功的梯子往上爬，领导则判断这个梯子是否搭在了正确的墙上。<br>个人生活中的领导意识则更为匮乏，很多人连自己的价值观都没有搞清楚，就忙于提高效率，制定目标或完成任务。</p>
<h2 id="改写人生剧本：成为自己的第一次创造者"><a href="#改写人生剧本：成为自己的第一次创造者" class="headerlink" title="改写人生剧本：成为自己的第一次创造者"></a>改写人生剧本：成为自己的第一次创造者</h2><p>以终为始意味着要到这清晰的方向和价值观来扮演自己的家长角色或其他角色，要为自己人生的第一次创造负责，为改写自己的人生剧本负责，从而使决定行为和态度的思维方式真正符合自己的价值观和正确原则。</p>
<h2 id="个人使命宣言"><a href="#个人使命宣言" class="headerlink" title="个人使命宣言"></a>个人使命宣言</h2><p>以终为始最有效的方法，就是撰写一份个人使命宣言，即人生哲学或基本信念。宣言主要说明自己想成为怎样的人（品德），成就什么样的事业（贡献和成就）及为此奠基的价值观和原则。</p>
<h2 id="核心区"><a href="#核心区" class="headerlink" title="核心区"></a>核心区</h2><p>核心是安全感、人生方向、智慧与力量的源泉。</p>
<ul>
<li>安全感：代表价值观、认同、情感的归属、自尊自重与拥有个人的基本能力。</li>
<li>人生方向：是“地图”和内心的准绳，人类以此为解释外界事物的理据以及决策与行为的原则和内在标准。</li>
<li>智慧：是人类对生命的认知、对平衡的感知和对事物间联系的理解，包括判断力、洞察力和理解力，是这些能力的统一体。</li>
<li>力量：指采取行动、达成目标的能力，它是做出抉择的关键性力量，也包括培育更有效的习惯以代理顽固旧习的能力。</li>
</ul>
<h2 id="各种生活中心"><a href="#各种生活中心" class="headerlink" title="各种生活中心"></a>各种生活中心</h2><p>休太长的假，看太多的电影或电视，打太多的电子游戏，长期无所事事，都等于浪费生命，无益于增长智慧，激发潜能，增进安全感或指引人生，只不过制造更多的<strong>空虚</strong>而已。</p>
<h2 id="以原则为中心"><a href="#以原则为中心" class="headerlink" title="以原则为中心"></a>以原则为中心</h2><h2 id="撰写使命宣言并付诸实践"><a href="#撰写使命宣言并付诸实践" class="headerlink" title="撰写使命宣言并付诸实践"></a>撰写使命宣言并付诸实践</h2><h2 id="唯有参与-才有认同"><a href="#唯有参与-才有认同" class="headerlink" title="唯有参与 才有认同"></a>唯有参与 才有认同</h2>
      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

        
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block home" lang="en">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2021/07/08/USB%E7%BD%91%E7%BB%9C%E8%AE%BE%E5%A4%87%E9%A9%B1%E5%8A%A8/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="Z.J. Jiang">
      <meta itemprop="description" content="about the single image super-resolution and face hallucination">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="SRCNN">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          
            <a href="/2021/07/08/USB%E7%BD%91%E7%BB%9C%E8%AE%BE%E5%A4%87%E9%A9%B1%E5%8A%A8/" class="post-title-link" itemprop="url">USB网络设备驱动</a>
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">Posted on</span>

              <time title="Created: 2021-07-08 23:31:57" itemprop="dateCreated datePublished" datetime="2021-07-08T23:31:57+08:00">2021-07-08</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">Edited on</span>
                <time title="Modified: 2021-10-20 22:32:15" itemprop="dateModified" datetime="2021-10-20T22:32:15+08:00">2021-10-20</time>
              </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h1 id="什么是USB网络设备驱动。"><a href="#什么是USB网络设备驱动。" class="headerlink" title="什么是USB网络设备驱动。"></a>什么是USB网络设备驱动。</h1><h1 id="网络设备驱动"><a href="#网络设备驱动" class="headerlink" title="网络设备驱动"></a>网络设备驱动</h1><h1 id="USB设备驱动"><a href="#USB设备驱动" class="headerlink" title="USB设备驱动"></a>USB设备驱动</h1>
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/2021/07/08/USB%E7%BD%91%E7%BB%9C%E8%AE%BE%E5%A4%87%E9%A9%B1%E5%8A%A8/#more" rel="contents">
                Read more &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

        
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block home" lang="en">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2021/06/07/%E4%BF%A1%E5%8F%B7%E5%AE%89%E5%85%A8%E5%87%BD%E6%95%B0/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="Z.J. Jiang">
      <meta itemprop="description" content="about the single image super-resolution and face hallucination">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="SRCNN">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          
            <a href="/2021/06/07/%E4%BF%A1%E5%8F%B7%E5%AE%89%E5%85%A8%E5%87%BD%E6%95%B0/" class="post-title-link" itemprop="url">信号安全函数</a>
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">Posted on</span>

              <time title="Created: 2021-06-07 22:49:28" itemprop="dateCreated datePublished" datetime="2021-06-07T22:49:28+08:00">2021-06-07</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">Edited on</span>
                <time title="Modified: 2021-07-08 23:25:09" itemprop="dateModified" datetime="2021-07-08T23:25:09+08:00">2021-07-08</time>
              </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h1 id="Overview"><a href="#Overview" class="headerlink" title="Overview"></a>Overview</h1><p>天啊，怎么改了几行代码就改出了一个惊天大的大Bug。居然导致死锁了，这是怎么回事呢，且让我一一道来。</p>
<p><a href="https://blog.csdn.net/hxlawf/article/details/98961011" target="_blank" rel="noopener">https://blog.csdn.net/hxlawf/article/details/98961011</a><br>
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/2021/06/07/%E4%BF%A1%E5%8F%B7%E5%AE%89%E5%85%A8%E5%87%BD%E6%95%B0/#more" rel="contents">
                Read more &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

        
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block home" lang="en">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2021/05/26/Linux-kernel-module/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="Z.J. Jiang">
      <meta itemprop="description" content="about the single image super-resolution and face hallucination">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="SRCNN">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          
            <a href="/2021/05/26/Linux-kernel-module/" class="post-title-link" itemprop="url">Linux kernel module</a>
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">Posted on</span>
              

              <time title="Created: 2021-05-26 23:26:54 / Modified: 23:45:13" itemprop="dateCreated datePublished" datetime="2021-05-26T23:26:54+08:00">2021-05-26</time>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h1 id="什么是内核模块"><a href="#什么是内核模块" class="headerlink" title="什么是内核模块"></a>什么是内核模块</h1><p>内核模块是可以根据需要加载和卸载到内核中的代码片段。它们扩展了内核的功能，而无需重新启动系统。例如，一种类型的内核模块是设备驱动程序，它允许内核访问连接到系统的硬件(例如nvmp中GPIO驱动电机就编译成了内核模块，在比如wifi驱动)。如果没有内核模块，我们将不得不构建庞大的内核，并将新功能直接添加到内核image中。除了拥有更大的内核外，这还有一个缺点，即每次需要新功能时都需要重新构建和重新启动内核。<br>
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/2021/05/26/Linux-kernel-module/#more" rel="contents">
                Read more &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

        
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block home" lang="en">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2021/04/19/Static-Link/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="Z.J. Jiang">
      <meta itemprop="description" content="about the single image super-resolution and face hallucination">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="SRCNN">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          
            <a href="/2021/04/19/Static-Link/" class="post-title-link" itemprop="url">Static Link</a>
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">Posted on</span>

              <time title="Created: 2021-04-19 23:46:56" itemprop="dateCreated datePublished" datetime="2021-04-19T23:46:56+08:00">2021-04-19</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">Edited on</span>
                <time title="Modified: 2021-11-30 23:36:20" itemprop="dateModified" datetime="2021-11-30T23:36:20+08:00">2021-11-30</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">In</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/C/" itemprop="url" rel="index">
                    <span itemprop="name">C</span>
                  </a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h1 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h1><p>在日常的开发中很多时候都会遇到链接问题。比如，缺少模块、缺少库或者库版本不兼容导致的链接问题；错误定义多个全局变量导致程序运行产生不可预知的错误。为了减少这些错误的发生，我们应当理解链接过程。本文主要讨论静态链接。</p>
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/2021/04/19/Static-Link/#more" rel="contents">
                Read more &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

        
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block home" lang="en">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2020/06/03/Redis-%E6%95%B4%E6%95%B0%E9%9B%86%E5%90%88/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="Z.J. Jiang">
      <meta itemprop="description" content="about the single image super-resolution and face hallucination">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="SRCNN">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          
            <a href="/2020/06/03/Redis-%E6%95%B4%E6%95%B0%E9%9B%86%E5%90%88/" class="post-title-link" itemprop="url">Redis 整数集合</a>
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">Posted on</span>
              

              <time title="Created: 2020-06-03 11:12:04 / Modified: 14:34:34" itemprop="dateCreated datePublished" datetime="2020-06-03T11:12:04+08:00">2020-06-03</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">In</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Redis/" itemprop="url" rel="index">
                    <span itemprop="name">Redis</span>
                  </a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
          <h1 id="整数集合的实现"><a href="#整数集合的实现" class="headerlink" title="整数集合的实现"></a>整数集合的实现</h1><p>整数集合(intset)是Redis用于保存整数值的集合抽象数据结构，它可以保存类型为<br>int16_t、int32_t、int64_t的整数值。<br><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">typedef</span> <span class="class"><span class="keyword">struct</span> <span class="title">intset</span> &#123;</span></span><br><span class="line">    <span class="comment">// 编码方式</span></span><br><span class="line">    <span class="keyword">uint32_t</span> encoding;</span><br><span class="line">    <span class="comment">// 元素的个数</span></span><br><span class="line">    <span class="keyword">uint32_t</span> length;</span><br><span class="line">    <span class="comment">// 保存元素的数组</span></span><br><span class="line">    <span class="keyword">int8_t</span> contents[];</span><br><span class="line">&#125; intset;</span><br></pre></td></tr></table></figure><br>
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/2020/06/03/Redis-%E6%95%B4%E6%95%B0%E9%9B%86%E5%90%88/#more" rel="contents">
                Read more &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    
      <footer class="post-footer">
        <div class="post-eof"></div>
      </footer>
  </article>
  
  
  

  </div>

  
  <nav class="pagination">
    <span class="page-number current">1</span><a class="page-number" href="/page/2/">2</a><span class="space">&hellip;</span><a class="page-number" href="/page/5/">5</a><a class="extend next" rel="next" href="/page/2/"><i class="fa fa-angle-right" aria-label="Next page"></i></a>
  </nav>



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let activeClass = CONFIG.comments.activeClass;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          Table of Contents
        </li>
        <li class="sidebar-nav-overview">
          Overview
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">Z.J. Jiang</p>
  <div class="site-description" itemprop="description">about the single image super-resolution and face hallucination</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">42</span>
          <span class="site-state-item-name">posts</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">11</span>
        <span class="site-state-item-name">categories</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">1</span>
        <span class="site-state-item-name">tags</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/jzijin" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;jzijin" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="/atom.xml" title="RSS → &#x2F;atom.xml"><i class="fa fa-fw fa-rss"></i>RSS</a>
      </span>
  </div>


  <div class="links-of-blogroll motion-element">
    <div class="links-of-blogroll-title">
      <i class="fa fa-fw fa-link"></i>
      Links
    </div>
    <ul class="links-of-blogroll-list">
        <li class="links-of-blogroll-item">
          <a href="http://www.njust.edu.cn/" title="http:&#x2F;&#x2F;www.njust.edu.cn" rel="noopener" target="_blank">南京理工大学</a>
        </li>
        <li class="links-of-blogroll-item">
          <a href="http://ehall.njust.edu.cn/new/index.html" title="http:&#x2F;&#x2F;ehall.njust.edu.cn&#x2F;new&#x2F;index.html" rel="noopener" target="_blank">南京理工大学智慧服务</a>
        </li>
        <li class="links-of-blogroll-item">
          <a href="http://lib.njust.edu.cn/" title="http:&#x2F;&#x2F;lib.njust.edu.cn&#x2F;" rel="noopener" target="_blank">南京理工大学图书馆</a>
        </li>
    </ul>
  </div>

      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Z.J. Jiang</span>
</div>
  <div class="powered-by">Powered by <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> v4.2.0
  </div>
  <span class="post-meta-divider">|</span>
  <div class="theme-info">Theme – <a href="https://pisces.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Pisces</a> v7.6.0
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>




  















  

  
      
<script type="text/x-mathjax-config">
    MathJax.Ajax.config.path['mhchem'] = '//cdn.jsdelivr.net/npm/mathjax-mhchem@3';

  MathJax.Hub.Config({
    tex2jax: {
      inlineMath: [ ['$', '$'], ['\\(', '\\)'] ],
      processEscapes: true,
      skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
    },
    TeX: {
        extensions: ['[mhchem]/mhchem.js'],
      equationNumbers: {
        autoNumber: 'AMS'
      }
    }
  });

  MathJax.Hub.Register.StartupHook('TeX Jax Ready', function() {
    MathJax.InputJax.TeX.prefilterHooks.Add(function(data) {
      if (data.display) {
        var next = data.script.nextSibling;
        while (next && next.nodeName.toLowerCase() === '#text') {
          next = next.nextSibling;
        }
        if (next && next.nodeName.toLowerCase() === 'br') {
          next.parentNode.removeChild(next);
        }
      }
    });
  });

  MathJax.Hub.Queue(function() {
    var all = MathJax.Hub.getAllJax(), i;
    for (i = 0; i < all.length; i += 1) {
      element = document.getElementById(all[i].inputID + '-Frame').parentNode;
      if (element.nodeName.toLowerCase() == 'li') {
        element = element.parentNode;
      }
      element.classList.add('has-jax');
    }
  });
</script>
<script>
  NexT.utils.getScript('//cdn.jsdelivr.net/npm/mathjax@2/MathJax.js?config=TeX-AMS-MML_HTMLorMML', () => {
    MathJax.Hub.Typeset();
  }, window.MathJax);
</script>

    

  

</body>
</html>
